package com.dartfar.base.action;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.struts2.ServletActionContext;

public class Test2 {

	    public static int convertPDF2SWF(String sourcePath, String destPath, String fileName) throws IOException {  
	        //目标路径不存在则建立目标路径  
	        File dest = new File(destPath);  
	        if (!dest.exists()) dest.mkdirs();  
	          
	        //源文件不存在则返回  
	        File source = new File(sourcePath);  
	        if (!source.exists()) return 0;  
	          
	        //调用pdf2swf命令进行转换  
	        String command = "C:\\Program Files\\SWFTools\\pdf2swf.exe" + " -o \"" + destPath + "\\" + fileName + "\"  -s flashversion=9 \"" + sourcePath + "\"";
	        
	        //COMMAND: C:\Program Files\SWFTools\pdf2swf.exe -o C:\Tomcat6\webapps\ROOT\SwfNews/1211031525349667.swf -s flashversion=9 C:\Tomcat6/NewsUpload/1211031525349667.pdf

	        System.out.println("command: " + command);
	        Process pro = Runtime.getRuntime().exec(command);  
	          
	        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(pro.getInputStream()));  
	        while (bufferedReader.readLine() != null);   
	          
	        try {  
	            pro.waitFor();  
	        } catch (InterruptedException e) {  
	            // TODO Auto-generated catch block  
	            e.printStackTrace();  
	        }  
	          
	        return pro.exitValue();  
	          
	    }  

    
    public static void main(String []args) throws IOException {  
        //String sourcePath = "c:\\学健纪字【2012】第025号 2012年10月30日周例会会议纪要.pdf";  
        //String destPath = "c:\\";  
        //String fileName = "1211031525349667.swf";  
        //Test2.convertPDF2SWF(sourcePath, destPath, fileName);  
    	
    	String str = "\\" + "总公司" + "\\" + "子公司";
    	System.out.println(str);
    	System.out.println("SSSS：" + str.substring(0, str.lastIndexOf("\\")));
    	
    	
    }  
	
}
